package com.luo.controller;

import com.alibaba.fastjson.JSON;
import com.luo.model.ResultObj;
import com.luo.util.RedisUtil;
import redis.clients.jedis.Jedis;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Set;

/**
 * 功能：
 * 作者：Luo。
 * 日期：2024/1/26 15:53
 */
@WebServlet("/adminExitLogin")
public class AdminLoginExitController extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ResultObj resultObj = new ResultObj();
        String token = req.getParameter("Authorization");
        token = token.substring(token.indexOf(" ") + 1);
        // 到redis数据库删除当前token的值
        Jedis jedis = RedisUtil.getJedis();
        // 使用 hdel 删除该token的用户信息
        Long del = jedis.del(token);
        resultObj.setCode("1");
        resultObj.setMsg("token删除成功");
        resultObj.setResult(del);
        String jsonString = JSON.toJSONString(resultObj);
        resp.getWriter().write(jsonString);
        resp.getWriter().close();
    }
}
